package com.jcnet.bizaia;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuItem;
import com.jcnet.bizaia.adapter.SearchListAdapter;
import com.jcnet.bizaia.bean.SearchBean;

public class SearchListActivity extends SherlockActivity  implements OnItemClickListener{

	private ListView listView;
	
	private List<SearchBean>searchBeans;
	
	private SearchListAdapter searchListAdapter;
	
	/*public static final int ADRESS_CODE_REQUEST = "ADRESS_CODE_REQUEST".hashCode();
	public static final int DATE_CODE_REQUEST = "DATE_CODE_REQUEST".hashCode();
	public static final int BISNIESS_CODE_REQUEST = "BISNIESS_CODE_REQUEST".hashCode();*/
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search_list_view);
		
		searchBeans = new ArrayList<SearchBean>();
		
		searchBeans.clear();
		
		searchBeans = (List<SearchBean>) getIntent().getSerializableExtra("listVa");
		
		
		listView = (ListView)findViewById(R.id.searchList);
		
		searchListAdapter = new SearchListAdapter(this,	 searchBeans);
		
		listView.setAdapter(searchListAdapter);
		
		listView.setOnItemClickListener(this);
		listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
		initActionBars();
	}
	
	
	

	private void initActionBars() {
		// TODO Auto-generated method stub
		ActionBar actionBar = getSupportActionBar();
		actionBar.setDisplayShowTitleEnabled(true);   //是都显示标题
		actionBar.setDisplayHomeAsUpEnabled(true);  //是都显示返回箭头
		getSupportActionBar().setDisplayShowHomeEnabled(false);   //   是都显示logo
		actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.top_bg));
		actionBar.show();
	}
	

	@Override
	public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
		// TODO Auto-generated method stub
		//getSupportMenuInflater().inflate(R.menu.main_menu, menu);
		return super.onCreateOptionsMenu(menu);
	}
	
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			break;

		default:
			break;
		}
		
		
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		searchListAdapter.setSelectedItem(arg2);
		searchListAdapter.notifyDataSetInvalidated();
		Intent intent = new Intent();
		intent.putExtra("resultBean", searchBeans.get(arg2));
		setResult(DiscussSearchActivity.RESULT_CODE,intent);
		finish();
		
	}
	
	
	
	
}
